﻿#include "HalconImageWidget.h"
#include <QHBoxLayout>>
#include <QVBoxLayout>

HalconImageWidget::HalconImageWidget(QWidget *parent)
    : QWidget{parent}
{
    setupUI();
    connect(mWindow, &HalconWindowWidget::sigPosRGBValue, this, &HalconImageWidget::onPosRGBValue);
}

void HalconImageWidget::setImage(const HObject& image)
{
    mWindow->setImage(image);
    int width = HImage(image).Width().I();
    int height = HImage(image).Height().I();
    lblImgSize->setText(QString("%1,%2").arg(width).arg(height));
}

void HalconImageWidget::setupUI()
{
    mWindow = new HalconWindowWidget();
    lblImgSize = new QLabel();
    lblCurPos = new QLabel();
    lblGrayValue = new QLabel();

    QVBoxLayout* vLayout = new QVBoxLayout();
    this->setLayout(vLayout);
    QHBoxLayout* hLayout = new QHBoxLayout();
    vLayout->addWidget(mWindow);
    vLayout->addLayout(hLayout);

    hLayout->addWidget(new QLabel("图像尺寸"));
    hLayout->addWidget(lblImgSize);
    hLayout->addWidget(new QLabel("位置"));
    hLayout->addWidget(lblCurPos);
    hLayout->addWidget(new QLabel("RGB"));
    hLayout->addWidget(lblGrayValue);
}

void HalconImageWidget::onPosRGBValue(const QPoint &pos, const QColor &color)
{
    lblCurPos->setText(QString("%1,%2").arg(pos.y()).arg(pos.x()));
    lblGrayValue->setText(QString("%1,%2,%3").arg(color.red()).arg(color.green()).arg(color.blue()));
}
